package com.yjf.ljr.activity;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.yjf.ljr.R;
import com.yjf.ljr.application.MyApplication;
import com.yjf.ljr.common.CommonData;
import com.yjf.ljr.dataclass.AcountManageDataClass;
import com.yjf.ljr.dataclass.AcountManageDataClass.AcountManageDataInfo;
import com.yjf.ljr.dataclass.EasyDataClass;
import com.yjf.ljr.dataclass.MyAccountDataClass;
import com.yjf.ljr.dataclass.MyAccountDataClass.MyAccountInfo;
import com.yjf.ljr.parser.RequestBuilder.RequestObject;
import com.yjf.ljr.util.AppUtil;
import com.yjf.ljr.util.SPreferences;
import com.yjf.ljr.view.RunningTextView;
import com.yjf.ljr.view.XListView;
import com.yjf.ljr.view.XListView.IXListViewListener;

public class MyAccountActivity extends IjActivity implements OnClickListener {

	public static boolean gIsLoginServer = false;

	/** 初始化我的账户 jinji0625/z111111 **/
	@ID("tv_invest_account")
	private TextView mTvInvestAccount; // TAB 我的账户
	@ID("tvPropertyAll")
	private TextView mTvPropertyAll; // 资产总额
	@ID("tvPropertyBalance")
	private TextView mTvPropertyAvailable; // 可用余额
	@ID("tvReceivePrincipal")
	private TextView mTvReceivePrincipal; // 待收本金
	@ID("tvPropertyFreeze")
	private TextView mTvPropertyFreeze; // 冻结金额
	@ID("tvReceiveIncome")
	private TextView mTvReceiveIncome; // 待收收益
	@ID("linLayLoadFail")
	private LinearLayout mLlLoadFailed;
	@ID("llInvestAccount")
	private LinearLayout mLlInvestAccount;
	@ID("homepg_invest_content")
	private LinearLayout mLlhomepg_invest_content;
	@ID("llAccountItems")
	private LinearLayout mLlAccountItems;
	@ID("llProjectInvest")
	private LinearLayout mLlProjectInvest; // 投资的项目
	@ID("llTransactionDetail")
	private LinearLayout mLlTransactionDetail; // 交易明细
	@ID("llCustomManage")
	private LinearLayout mLlCustomManage; // 客户管理
	@ID("llBusinessManage")
	private LinearLayout mLlBusinessManage; // 业务管理
	@ID("llmycount")
	private LinearLayout mLlmycount; //
	// @ID("llAccountInfo")
	// private LinearLayout mLlAccountInfo; // 账户信息
	@ID("llAccountManage")
	private LinearLayout mLlAccountManage; // 账户信息
	@ID("llnoactivation")
	private LinearLayout mLlnoactivation; //
	@ID("tv_title_right")
	private TextView mTvExit;

	@ID("llRedPacket")
	private LinearLayout mLlRedPacket;// 红包
	@ID("llQrCode")
	private LinearLayout mLlQrCode;// 我的二维码
	private String mQrCodeUrl;

	private boolean mHasAccountInfo = false;

	@ID("btAccountRecharge")
	private Button mBtAccountRecharge;
	@ID("homeListViewMain")
	private XListView mLvAccount;

	private boolean mIsLoadingMore = false;
	private boolean isOnLine = false;

	@ID("rlPropertyAll")
	private RelativeLayout mRlPropertyAll; // 资产总额
	@ID("llPropertyAllList")
	private LinearLayout mLlPropertyAllList; // 资产总额列表
	@ID("ivArrowDown")
	private ImageView mIvArrowDown; // 资产总额下箭头
	@ID("tvCustomerName")
	private TextView mTvCustomerName;
	@ID("tvIncomedAll")
	private TextView mTvIncomedAll; // 已收收益
	@ID("tvIncomeAll")
	private RunningTextView/* TextView */mTvIncomeAll; // 收益总金额(元)
	@ID("tvInvestAll")
	private TextView mTvInvestAll; // 您当前投资总金额

	@ID("btAccountWithdraw")
	private Button mBtAccountWithdraw;

	@ID("rlWithdrawContainer")
	private RelativeLayout mRlWithdrawContainer;

	@ID("account_scroll")
	private ScrollView accountScroll;

	private MyApplication myApplication;
	private static final int ACCOUNT_MANAGE = 1006;
	private boolean returnAcountFlag = true;

	private final int RECHARGE_REQUEST = 1007;

	public static boolean isNeedFresh = false;
	
	private boolean isActive = false;
	private String availableBalance;
	
	@ID("llDebtor")
	private LinearLayout mLlDebtor;// 债权转让

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.homepg_invest_account);
		myApplication = (MyApplication) getApplication();
		initControls();
	}

	@Override
	protected void onResume() {
		if (!mHasAccountInfo || isNeedFresh) {
			isNeedFresh = false;
			showProgressDialog();
			new AccountOverviewTask().execute();
		}
		super.onResume();
	}

	/** 初始化控件 **/
	private void initControls() {
		findViewById(R.id.btn_title_left).setVisibility(View.GONE);
		setTitleStr("我的账户");
		mTvExit.setText("退出");
		mTvExit.setVisibility(View.GONE);
		mTvExit.setOnClickListener(this);

		View vContent = LayoutInflater.from(this).inflate(R.layout.homepg_invest_content, null);
		initComponents(this, vContent, this);
		mLlDebtor.setOnClickListener(this);
		mLvAccount.addHeaderView(vContent);
		mLvAccount.setAdapter(null);
		mLvAccount.setPullLoadEnable(true);
		mLvAccount.setPullRefreshEnable(true);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		mLvAccount.setRefreshTime(sdf.format(new Date()));
		mLvAccount.mFooterView.hide(); // 隐藏更多

		mLlRedPacket.setOnClickListener(this);
		mLlQrCode.setOnClickListener(this);
		mLlInvestAccount.setVisibility(View.GONE);
		mLlAccountItems.setVisibility(View.GONE);
		mRlWithdrawContainer.setVisibility(View.GONE);
		mLlProjectInvest.setOnClickListener(this);
		mLlTransactionDetail.setOnClickListener(this);
		mLlCustomManage.setOnClickListener(this);
		mLlBusinessManage.setOnClickListener(this);
		// mLlAccountInfo.setOnClickListener(this);
		mLlAccountManage.setOnClickListener(this);
		mBtAccountRecharge.setOnClickListener(this);
		mLlmycount.setVisibility(View.GONE);
		mLlLoadFailed.setOnClickListener(this);
		mLlLoadFailed.setVisibility(View.GONE);
		mLvAccount.setXListViewListener(new IXListViewListener() {
			@Override
			public void onRefresh() {
				if (mIsLoadingMore) {
					return;
				}
				mIsLoadingMore = true;
				new AccountOverviewTask().execute();
			}

			@Override
			public void onLoadMore() {
			}
		});
		mRlPropertyAll.setOnClickListener(this);
		mLlPropertyAllList.setOnClickListener(this);
		mIvArrowDown.setTag("fold");

		mBtAccountWithdraw.setOnClickListener(this);

		accountScroll.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if ("unfold".equals(mIvArrowDown.getTag())) {
					Animation foldAnim = AnimationUtils.loadAnimation(mContext, R.anim.help_arrow_fold_rotate);
					foldAnim.setFillAfter(true);
					mIvArrowDown.startAnimation(foldAnim);
					mIvArrowDown.setTag("fold");
					mLlPropertyAllList.setVisibility(View.GONE);
					return true;
				} else {
					return false;
				}
			}
		});
	}

	@Override
	public void onClick(View v) {
		if (v.getId() != R.id.llPropertyAllList) {
			if ("unfold".equals(mIvArrowDown.getTag())) {
				Animation foldAnim = AnimationUtils.loadAnimation(mContext, R.anim.help_arrow_fold_rotate);
				foldAnim.setFillAfter(true);
				mIvArrowDown.startAnimation(foldAnim);
				mIvArrowDown.setTag("fold");
				mLlPropertyAllList.setVisibility(View.GONE);
				return;
			}
		}

		switch (v.getId()) {
		case R.id.linLayLoadFail:
			showProgressDialog();
			new AccountOverviewTask().execute();
			mLlLoadFailed.setVisibility(View.GONE);
			break;
		case R.id.llnoactivation:
			showProgressDialog();
			new AccountOverviewTask().execute();
			break;
		case R.id.llProjectInvest: // 投资的项目
			startActivityForResult(new Intent(MyAccountActivity.this, InvestProjectActivity.class), RECHARGE_REQUEST);
			break;
		case R.id.llTransactionDetail: // 交易明细
			startActivityForResult(new Intent(MyAccountActivity.this, PaymentDetailsActivity.class), RECHARGE_REQUEST);
			break;
		case R.id.llCustomManage: // 客户管理
			startActivityForResult(new Intent(MyAccountActivity.this, CustomerManageActivity.class), RECHARGE_REQUEST);
			break;
		case R.id.llBusinessManage: // 业务管理
			startActivityForResult(new Intent(MyAccountActivity.this, BusinessManagementActivity.class),
					RECHARGE_REQUEST);
			break;
		case R.id.llAccountManage:// 账户管理
			startActivityForResult((new Intent(MyAccountActivity.this, AcountManageActivity.class)), ACCOUNT_MANAGE);
			break;
		case R.id.tv_title_right:
			exitApp();
			// showProgressDialog();
			// new ExitTask().execute();

			break;
		case R.id.llRedPacket:// 红包管理
			startActivityForResult(new Intent(MyAccountActivity.this, RedPacketActivity.class), RECHARGE_REQUEST);
			break;
		case R.id.llQrCode:// 我的二维码
			Intent i = new Intent(MyAccountActivity.this, QrCodeActivity.class);
			i.putExtra("QrCodeUrl", mQrCodeUrl);
			startActivity(i);
			break;
		case R.id.btAccountRecharge:// 充值
			Intent rechargeIntent = new Intent(MyAccountActivity.this, RechargeActivity.class);
			if(isActive) {
				startActivityForResult(rechargeIntent,RECHARGE_REQUEST);
			} else {			
				new AcountManageTask(rechargeIntent).execute();
			}
			break;
		case R.id.rlPropertyAll: // 账户总额
			if ("fold".equals(mIvArrowDown.getTag())) { // 展开
				Animation foldAnim = AnimationUtils.loadAnimation(mContext, R.anim.help_arrow_unfold_rotate);
				foldAnim.setFillAfter(true);
				mIvArrowDown.startAnimation(foldAnim);
				mIvArrowDown.setTag("unfold");

				ScaleAnimation animShow = new ScaleAnimation(1.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f,
						Animation.RELATIVE_TO_SELF, 0.0f);
				animShow.setDuration(200);// 设置动画持续时间

				mLlPropertyAllList.startAnimation(animShow);
				mLlPropertyAllList.setVisibility(View.VISIBLE);
				animShow.setAnimationListener(new AnimationListener() {
					@Override
					public void onAnimationStart(Animation animation) {
						// mLlPropertyAllList.setVisibility(View.VISIBLE);
					}

					@Override
					public void onAnimationRepeat(Animation animation) {
					}

					@Override
					public void onAnimationEnd(Animation animation) {
					}
				});
			} else if ("unfold".equals(mIvArrowDown.getTag())) {
				Animation foldAnim = AnimationUtils.loadAnimation(mContext, R.anim.help_arrow_fold_rotate);
				foldAnim.setFillAfter(true);
				mIvArrowDown.startAnimation(foldAnim);
				mIvArrowDown.setTag("fold");

				ScaleAnimation animaHide = new ScaleAnimation(1.0f, 1.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f,
						Animation.RELATIVE_TO_SELF, 0.0f);
				animaHide.setDuration(200);// 设置动画持续时间

				mLlPropertyAllList.startAnimation(animaHide);
				animaHide.setAnimationListener(new AnimationListener() {
					@Override
					public void onAnimationStart(Animation animation) {
					}

					@Override
					public void onAnimationRepeat(Animation animation) {
					}

					@Override
					public void onAnimationEnd(Animation animation) {
						mLlPropertyAllList.setVisibility(View.GONE);
					}
				});
			}
			break;
		case R.id.btAccountWithdraw:
			Intent withdrawIntent = new Intent(MyAccountActivity.this, WithdrawActivity.class);
			withdrawIntent.putExtra("availableBalance", availableBalance);
			if(isActive) {
				startActivityForResult(withdrawIntent,RECHARGE_REQUEST);
			} else {
				new AcountManageTask(withdrawIntent).execute();
			}
			break;
		case R.id.llDebtor:
			// 债权转让
			startActivity(new Intent(MyAccountActivity.this, MyDebtorActivity.class));
			break;
		default:
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
		mIsLoadingMore = false;
		mHasAccountInfo = false;
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
			case CommonData.REQUEST_CODE_LOGIN:
				if (CommonData.FLAG_LOGIN_SERVER) {
					CommonData.FLAG_LOGIN_SERVER = false;
					gIsLoginServer = true;
				} else {
					if (!isOnLine) {
						mLlLoadFailed.setVisibility(View.VISIBLE);
					} else {
						mLlLoadFailed.setVisibility(View.GONE);
					}
				}
				break;
			case ACCOUNT_MANAGE:
				returnAcountFlag = false;
				new ExitTask().execute();
				break;

			}
		} else {
			if (requestCode == CommonData.REQUEST_CODE_LOGIN) {
				if (!(intent != null && intent.getBooleanExtra("fromLockPattern", false))) {
					GroupActivity.changeTab(0);
				}
			}
		}

		super.onActivityResult(requestCode, resultCode, intent);
	}

	/** 获取账户信息 **/
	class AccountOverviewTask extends AsyncTask<Void, Void, String> {

		private MyAccountDataClass dc = new MyAccountDataClass();

		@Override
		protected void onPreExecute() {			
			super.onPreExecute();
			isActive = false;
			availableBalance = "";
		}

		@Override
		protected String doInBackground(Void... params) {
			RequestObject reqObj = new RequestObject();
			reqObj.method = "appMeAccount";
			return requestDataAndGetErrorMsg(reqObj, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			dismissProgressDialog();
			mLvAccount.stopRefresh();
			mLvAccount.stopLoadMore();
			mIsLoadingMore = false;
			if ("-1".equals(dc.code)) {
				loginWebview();
				mLlmycount.setVisibility(View.GONE);
				mHasAccountInfo = true;
				isOnLine = false;
				return;
			}
			if ("-2".equals(dc.code)) {
				showToast("未对该角色开放app功能");
				return;
			}
			if (!TextUtils.isEmpty(result)) {
				showToast(result);
				mLlLoadFailed.setVisibility(View.VISIBLE);
				mLlmycount.setVisibility(View.GONE);
				mLlnoactivation.setVisibility(View.GONE);
				// showProgressDialog();
			} else {
				mRlWithdrawContainer.setVisibility(View.VISIBLE);
				mQrCodeUrl = dc.openInvestorUrl;
				if (dc.userInfos != null && dc.userInfos.size() > 1) {
					isOnLine = true;
					mLlLoadFailed.setVisibility(View.GONE);
					mLlnoactivation.setVisibility(View.GONE);
					mTvExit.setVisibility(View.VISIBLE);

					MyAccountInfo info = dc.userInfos.get(0);
					if (info != null) {
						if("1".equals(dc.activeAccount)) {
							isActive = true;
						} else {
							isActive = false;
						}
						availableBalance = info.available;
//						if ("2".equals(dc.activeAccount)) {
//							CustomDialog.Builder mBuilder = new CustomDialog.Builder(MyAccountActivity.this);
//							mBuilder.setTitle("账户未激活");
//							mBuilder.setMessage("请去激活");
//							mBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//
//								@Override
//								public void onClick(DialogInterface arg0, int arg1) {
//									// TODO Auto-generated method stub
//									mLlmycount.setVisibility(View.GONE);
//									mLlLoadFailed.setVisibility(View.GONE);
//									mLlnoactivation.setVisibility(View.VISIBLE);
//									mLlnoactivation.setOnClickListener(MyAccountActivity.this);
//								}
//							});
//							mBuilder.create().show();
//							return;
//						}
						
						mLlmycount.setVisibility(View.VISIBLE);
						mLlnoactivation.setVisibility(View.GONE);
						mLlnoactivation.setVisibility(View.GONE);
						mHasAccountInfo = true;
						mLlInvestAccount.setVisibility(View.VISIBLE);
                        String name = TextUtils.isEmpty(info.realName) ? info.userName : info.realName;
						AppUtil.setViewHtml(mTvCustomerName, "尊敬的客户 " + name/*info.realName*/ + "，您好！");
						if (TextUtils.isEmpty(info.investedProfitAmount)) {
							info.investedProfitAmount = "0.00";
						}
						try {
							mTvIncomeAll.playNumber(Double.parseDouble(info.investedProfitAmount));
						} catch (Exception e) {
							AppUtil.setViewHtml(mTvIncomeAll, info.investedProfitAmount);
						}
						String incomeAmount = "";
						String investAmount = "";
						if (TextUtils.isEmpty(info.paidInvestedAmount)) {
							incomeAmount = "0.00";
						} else {
							incomeAmount = "<font color='#ffffff'>" + info.paidInvestedAmount + "元" + "</font>";
						}
						if (TextUtils.isEmpty(info.totalInvestedAmount)) {
							investAmount = "0.00";
						} else {
							investAmount = "<font color='#ffffff'>" + info.totalInvestedAmount + "元" + "</font>";
						}
						AppUtil.setViewHtml(mTvIncomedAll, "已收益 " + incomeAmount);
						AppUtil.setViewHtml(mTvInvestAll, "您当前投资总金额 " + investAmount);

						String yuan = "<font color='#666666'>元</font>";
						AppUtil.setViewHtml(mTvPropertyAll, info.total + yuan);
						AppUtil.setViewHtml(mTvPropertyAvailable, info.available + yuan);
						AppUtil.setViewHtml(mTvReceivePrincipal, info.duein + yuan);
						AppUtil.setViewHtml(mTvPropertyFreeze, info.freeze + yuan);
						AppUtil.setViewHtml(mTvReceiveIncome, info.dueinProfit + yuan);
					}

					MyAccountInfo permission = dc.userInfos.get(1);
					if (permission != null) {
						PermissionCheck(permission);
					}
				} else {
					mLlnoactivation.setVisibility(View.GONE);
					mLlmycount.setVisibility(View.GONE);
					mLlLoadFailed.setVisibility(View.VISIBLE);
				}
			}
		}
	}

	private void PermissionCheck(MyAccountInfo permission) {
		mLlAccountItems.setVisibility(View.VISIBLE);
		mLlProjectInvest.setVisibility(View.GONE);
		mLlCustomManage.setVisibility(View.GONE);
		mLlBusinessManage.setVisibility(View.GONE);
		mLlRedPacket.setVisibility(View.GONE);
		mLlQrCode.setVisibility(View.GONE);
		if ("1".equals(permission.investProject)) {
			mLlProjectInvest.setVisibility(View.VISIBLE);
		}
		if ("1".equals(permission.tradeDetail)) {
			mLlTransactionDetail.setVisibility(View.VISIBLE);
		}
		if ("1".equals(permission.consumerManager)) {
			mLlCustomManage.setVisibility(View.VISIBLE);
		}
		if ("1".equals(permission.businessManager)) {
			mLlBusinessManage.setVisibility(View.VISIBLE);
		}
		if ("1".equals(permission.giftMoneyInfo)) { // 红包
			mLlRedPacket.setVisibility(View.VISIBLE);
		}
		if ("1".equals(permission.QRCode)) { // 我的二维码
			mLlQrCode.setVisibility(View.VISIBLE);
		}
	}

	/***
	 * 退出登录。调用接口
	 */
	/** 退出登陆 **/
	class ExitTask extends AsyncTask<Void, Void, String> {

		private EasyDataClass dc = new EasyDataClass();

		@Override
		protected String doInBackground(Void... params) {
			RequestObject reqObj = new RequestObject();
			reqObj.method = "logout";
			return requestDataAndGetErrorMsg(reqObj, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			dismissProgressDialog();
			CommonData.SESSIONID = "";
			gIsLoginServer = false;

			/** 清楚CookieManager中的cookie */
			CookieSyncManager.createInstance(mContext);
			CookieManager cookieManager = CookieManager.getInstance();
			cookieManager.removeSessionCookie();
			CookieSyncManager.getInstance().sync();

			// 隐藏我的账户
			mTvExit.setVisibility(View.GONE);
			mLlInvestAccount.setVisibility(View.GONE);
			mLlAccountItems.setVisibility(View.GONE);
			mRlWithdrawContainer.setVisibility(View.GONE);
			mHasAccountInfo = false;
			// showToast("已退出登录");
			if (returnAcountFlag) {
				GroupActivity.changeTab(0);
				CommonData.FLAG_LOGIN_SERVER = false;
			}
			returnAcountFlag = true;

			// 退出登陆，需将用户名清空
			CommonData.IS_LOGIN = false;
			SPreferences.clearPassword(MyAccountActivity.this);
			CommonData.USER_NAME = "";
			myApplication.stopAutoLogin();

		}
	}

	private void exitApp() {
		new AlertDialog.Builder(this).setTitle("提示").setIcon(R.drawable.icon_exit).setMessage("\n  确定要退出吗？\n")
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						showProgressDialog();
						new ExitTask().execute();
					}
				}).setNegativeButton("取消", null).show();
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		return false;
	}
	
	
	class AcountManageTask extends AsyncTask<Void, Void, String> {
		private AcountManageDataClass dc = new AcountManageDataClass();

		private Intent intent;
		public AcountManageTask(Intent intent) {
			this.intent = intent;
		}
		
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			showProgressDialog();
		}

		@Override
		protected String doInBackground(Void... params) {
			// TODO Auto-generated method stub
			RequestObject mObject = new RequestObject();
			mObject.method = "appAccountInfo";
			return requestDataAndGetErrorMsg(mObject, dc);
		}

		@Override
		protected void onPostExecute(String result) {	
			dismissProgressDialog();			
			if ("-1".equals(dc.code)) {
				loginWebview();
				mLlmycount.setVisibility(View.GONE);
				mHasAccountInfo = true;
				isOnLine = false;
				return;
			}
			if (!TextUtils.isEmpty(result)) {
				showToast(result);
			} else {
				AcountManageDataInfo data = dc.accountInfo;		
				final String mobile = data.mobile;
				
				String openStatus = getString(R.string.payment_status_on);
				String activeStatus = getString(R.string.payment_status_active);
				if(TextUtils.isEmpty(data.openState) || (!data.openState.equals(openStatus) && !data.openState.equals(activeStatus))) {
					dismissProgressDialog();
					AlertDialog.Builder builder = new AlertDialog.Builder(MyAccountActivity.this);
					builder.setTitle("提示");
					builder.setMessage("您的账户未激活，激活支付账户后方可充值、投资。");
					if(!TextUtils.isEmpty(mobile)) {
						builder.setPositiveButton("立即激活", new DialogInterface.OnClickListener(){

							@Override
							public void onClick(DialogInterface dialog, int which) {
								Intent intent = new Intent(MyAccountActivity.this,RegistrationActiveActivity.class);
								intent.putExtra("phoneNum", mobile);
								startActivity(intent);
							}							
						});
						builder.setNegativeButton("暂不激活", null);
					} else {
						builder.setPositiveButton("确定", null);
					}													
					AlertDialog dialog = builder.create();					
					dialog.show();
					return;
				}
				if(intent != null) {
					startActivityForResult(intent, RECHARGE_REQUEST);
				}				
            }

		}
	}

}
